<?php

class It_Model_EquipmentProject extends Zend_Db_Table_Abstract
{
    protected $_name = 'equipment_project';

    public function deleteProjectByEquipmentId ($equipmentId)
    {
    	$this->delete( array('equipmentId = ?' =>(int) $equipmentId ));
    }
    // chua su dung
    
    public function addEquipmentProject ($equipmentId, $projectId)
    {
//		var_dump($equipmentId, $projectId);exit;
        $data = array (
            'equipmentId' =>$equipmentId ,'projectId' => $projectId
        );
        try{
        	return $this->insert( $data );
        }
        catch(Zend_Exception $exp)
        {
        	//echo 'Error!: ' . $exp->getMessage();
        	return false;
        }
    }
    public function getProjectId($equipmentId)
    {
    	$select = $this->select()->from($this->_name)->where('equipmentId = ?',$equipmentId);
    	return $this->fetchRow($select);
    }
    public function getAllProjectName($equipmentId)
    {
    	$select = $this->select();
    	$select->from(array('ep'=>$this->_name))
    			->joinInner(array('p'=>'project'), 'ep.projectId = p.projectId')
    			->where('ep.equipmentId = ?',$equipmentId)
    			->setIntegrityCheck( false );
        $rs = $this->fetchAll( $select )->toArray();

        $arr = array();
        foreach($rs as $key =>$value)
        {
        	$arr[]= $value['projectName'];
        }
        return implode(',', $arr);
    }
    public function deleteEquipmentProject ($equipmentId, $projectId)
    {
        $this->delete( array('equipmentId = ?' =>(int) $equipmentId ,'projectId = ?' =>(int) $projectId  ));
    }
    public function updateEquipmentProject ($equipmentId, $data)
    {
    	$result = $this->update($data, array('equipmentId = ?' =>(int) $equipmentId));
    }
    public function findForSelect ()
    {

        $select = $this->select();
        return $this->fetchAll( $select );
    }

}

























